package com.ruoyi.web.controller.zsix;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.zsixOrg.GroupEntity;
import com.ruoyi.common.core.domain.zsixOrg.UserEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsix.domain.model.GroupUsersParams;
import com.ruoyi.zsix.service.IOrgManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/orgm")
public class orgManagementController extends BaseController {
    @Autowired
    private IOrgManagementService orgManagementService;

    /**
     * 获取组织结构数据
     * @return
     */
    @Log(title = "获取整个组织结构的数据" , businessType = BusinessType.EXPORT)
    @GetMapping("/getOrgData")
    public AjaxResult getOrgData(){
        return success(orgManagementService.getOrgData());
    }


    /**
     * 获取部门人员
     * @param response
     * @param departid
     * @return
     */
    @Log(title = "获取部门人员" , businessType = BusinessType.EXPORT)
    @GetMapping("/getUserByDepartId")
    public TableDataInfo getUserByDepartId(HttpServletResponse response,
                                           @RequestParam("departid") Long departid){
        startPage();
        List<UserEntity> list = orgManagementService.getUserByDepartId(departid);
        return getDataTable(list);
    }
    /**
     * 获取用户分组列表
     * @param
     * @return
     */
    @Log(title = "获取用户组列表" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/getGroupList")
    public TableDataInfo getGroupList(@RequestBody GroupEntity groupEntity){
        startPage();
        List<GroupEntity> list=orgManagementService.getGroupList(groupEntity);
        return getDataTable(list);
    }
    /**
     * 获取分组内的成员
     * @param
     * @return
     */
    @Log(title = "获取用户组中的人员" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/getUserByGorupId")
    public TableDataInfo getUserByGorupId(@RequestBody GroupEntity groupEntity){
        startPage();
        List<UserEntity> list=orgManagementService.getUserByGorupId(groupEntity);
        return getDataTable(list);
    }
    /**
     * 增加分组
     * @param groupEntity
     * @return
     */
    @Log(title = "增加用户组" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/addGroup")
    public AjaxResult addGroup(@RequestBody  GroupEntity groupEntity){
        return success(orgManagementService.addGroup(groupEntity));
    }

    /**
     * 更新分组
     * @param groupEntity
     * @return
     */
    @Log(title = "修改用户组" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/updataGroup")
    public AjaxResult updataGroup(@RequestBody GroupEntity groupEntity){
        return success(orgManagementService.updataGroup(groupEntity));
    }

    /**
     * 删除分组
     * @param groupEntity
     * @return
     */
    @Log(title = "删除用户组" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/deleteGroup")
    public AjaxResult deleteGroup(@RequestBody GroupEntity groupEntity){
        return success(orgManagementService.deleteGroup(groupEntity));
    }

    /**
     * 增加分组人员
     * @param param
     * @return
     */
    @Log(title = "增加用户组成员" , businessType = BusinessType.EXPORT)
    @PostMapping(value = "/addUserGroup")
    public AjaxResult addUserGroup(@RequestBody GroupUsersParams param){
        return success(orgManagementService.addUserGroup(param));
    }

    /**
     * 删除分组人员
     * @param username
     * @param groupid
     * @return
     */
    @Log(title = "删除用户组" , businessType = BusinessType.EXPORT)
    @GetMapping(value = "/deleteUserGroup")
    public AjaxResult deleteUserGroup(@RequestParam("username") String username,
                                     @RequestParam("groupid") String groupid){
        return success(orgManagementService.deleteUserGroup(username,groupid));
    }
}
